﻿using Api.WDS.Operate;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Api.WDS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ArticleController : ControllerBase
    {
        /// <summary>
        /// 发表文章
        /// </summary>
        /// <returns></returns>
        [HttpPost("Publish")]
        public IActionResult Publish()
        {
            var token = HttpContext.Request.Form["Token"];
            var title = HttpContext.Request.Form["Title"];
            var context = HttpContext.Request.Form["Context"];
            var classification = HttpContext.Request.Form["Classification"];
            var isPublic = HttpContext.Request.Form["IsPublic"];
            var isComment = HttpContext.Request.Form["IsComment"];
            return Ok(new ArticleOp().PublishArticle(new Models.VModels.V_Publish()
            {
                Token = token,
                Title = title,
                Context = context,
                Classification = Convert.ToInt32(classification),
                IsPublic = Convert.ToInt32(isPublic),
                IsComment = Convert.ToInt32(isComment)
            }));
        }

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <returns></returns>
        [HttpGet("Delete")]
        public IActionResult Delete()
        {
            var token = HttpContext.Request.Query["Token"];
            var articleId = HttpContext.Request.Query["ArticleId"];

            return Ok(new ArticleOp().DelArticle(token,articleId));
        }
    }
}
